package com.ruoyi.user.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.user.service.IAmapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/amap/direction")
public class AmapController {

    @Autowired
    private IAmapService amapService;

    @PreAuthorize("@ss.hasPermi('user:amap:direction')")
    @GetMapping("/driving")
    public AjaxResult driving(@RequestParam("origin") String origin,
                              @RequestParam("destination") String destination,
                              @RequestParam(value = "strategy", required = false) String strategy) {
        Object data = amapService.drivingDirection(origin, destination, strategy);
        return AjaxResult.success(data);
    }

    @PreAuthorize("@ss.hasPermi('user:amap:direction')")
    @GetMapping("/driving/polyline")
    public AjaxResult drivingPolyline(@RequestParam("origin") String origin,
                                      @RequestParam("destination") String destination,
                                      @RequestParam(value = "strategy", required = false) String strategy) {
        java.util.Map<String, Object> data = amapService.drivingPolylineData(origin, destination, strategy);
        return AjaxResult.success(data);
    }
}
